<?php
	class loaitivi{
		public $id;
		public $TenLoai;
		public $TrangThai;
		public function getAllLoaiTiviByWhere($where,$order){
			
			$db = new db();
			$db->getInstance();
			$sql = "select * from tblloaitv";
			if($where != '') $sql .= ' where ' . $where;
			if($order != '') $sql .= ' order by ' . $order;
			$rs = mysql_query($sql);
			while($rc = mysql_fetch_object($rs)){
				$lstLoaiTivi[] = $rc;	
			}
			return $lstLoaiTivi;
		}
		
		public function getLoaiTiviById($id){
			$db = new db();
			$db->getInstance();
			$sql = "Select * from tblloaitv where id = " . $id; 
			$rs = mysql_query($sql);
			$rc = mysql_fetch_object($rs);
			return $rc;
		}
		
		public function insert($loai){
			$db = new db();
			$db->getInstance();
			$sql = "Insert tblloaitv(TenLoai,TrangThai) values('".$loai->TenLoai."',".$loai->TrangThai.")"; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function update($loai){
			$db = new db();
			$db->getInstance();
			$sql = "Update tblloaitv set TenLoai='".$loai->TenLoai."',TrangThai=".$loai->TrangThai." where id =".$loai->id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
		
		public function delete($id){
			$db = new db();
			$db->getInstance();
			$sql = "delete from tblloaitv where id=".$id; //echo $sql; die;
			$rs = mysql_query($sql);
			if($rs) return true;
			else return false;
		}
	}
?>